<html lang="en">  
<head>  
    <title>Hello WebSocket</title>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script src="http://cdn.bootcss.com/stomp.js/2.3.3/stomp.js"></script>  
    <script type="text/javascript">  
        var stompClient = null;  
        function connect() {  
        	//stompClient = Stomp.client('ws://api.8582333.com/ws/websocket');
        	stompClient = Stomp.client('ws://127.0.0.1:8003/ws/websocket');
            var user_id=document.getElementById('fromuserid').value;
            var fromnickname=document.getElementById('fromnickname').value;
            var headers = {
            	id: user_id,
            	user_id: user_id,
            	fromnickname: fromnickname,
            	client:'PC'
            };
            stompClient.connect(headers, function(frame) {  
  				//个人
                stompClient.subscribe('/user/' + user_id + '/message',function(greeting){  
                    showGreeting(greeting.body);  
                }); 
            });  
        }  
        function disconnect() {  
            if (stompClient != null) {  
                stompClient.disconnect();  
            }  
        }
 		
        function sendToAll() {
        	var msg =document.getElementById('content').value;
        	msg = "&#x6240;&#x53";
            var content={
            	'msg': msg
            }
            var msg=JSON.stringify({
            	'mtype': 'user',
            	'content':  content
            	})
            stompClient.send("/sendToAll", {'token': '5c42d87cae6945bca87cc4673791b5f8'}, msg);
     	}
        function sendToUser() {
          var content={
                 	'msg': document.getElementById('content').value 
                 }
           var msg=JSON.stringify({
	           	'type': 'message',
	           	'mtype': 'user',
	           	'fromuserid': document.getElementById('fromuserid').value,
	           	'fromnickname': document.getElementById('fromnickname').value,
	           	'touserid': document.getElementById('fromuserid').value,
	           	'content':  content
           	})
          stompClient.send("/sendToUser", {'token': '5c42d87cae6945bca87cc4673791b5f8'}, msg);
     	}
        function showGreeting(message) {  
            var response = document.getElementById('response');  
            var p = document.createElement('p');  
            p.style.wordWrap = 'break-word';  
            p.appendChild(document.createTextNode(message));  
            response.appendChild(p);  
        }  
    </script>  
</head>  
<body>  
<noscript><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websocket relies on Javascript being enabled. Please enable  
    Javascript and reload this page!</h2></noscript>  
<div>  
    <div>  
        <button id="connect" onclick="connect();">Connect</button>  
        <button id="disconnect" onclick="disconnect();">Disconnect</button>  
    </div>
    <div id="conversationDiv">  
        <label>fromuserid</label><input type="text" id="fromuserid" value="1000000002"/>
        <label>fromnickname</label><input type="text" id="fromnickname" value="游客local_gexing"/>
    </div>
    <div>
    	<button id="sendtoall"  onclick="sendToAll();"><b>sendtoall</b></button> 
        <button id="sendtouser"  onclick="sendToUser();"><b>sendtouser</b></button> 
    </div>
    <div>
    	发送内容：<br><input type="text" id="content" style="height: 50px;width: 800px;"/>
    </div>
     <p id="response"></p> 
</div>  
</body>  
</html>  